<template>
    <view class="followDetails">
        <view class="trends">
            <view class="trends-name">
                <view class="trends-avatar">
                    <u-avatar class="avatar" size="40" :src="detailsData.avatar"></u-avatar>
                    <view class="trends-name-text">{{ detailsData.staffName }}</view>
                </view>
                <view class="trends-customer">{{ bus_followup_type[detailsData.followupType] }}</view>
            </view>
            <view class="trends-describe">{{ detailsData.followupContent }}</view>
            <view class="trends-state">
                <view><u-icon name="calendar" color="#677585" size="20"></u-icon><text>{{ detailsData.createTime }}</text></view>
                <view>来自客户：{{ detailsData.customerName }}</view>
            </view>
        </view>
        <!-- 切换 -->
        <view class="tab-box">
            <view v-for="item in tabList" :key="item.type" @click="tabIndex = item.type" :class="{ active: tabIndex == item.type }">{{ item.name }}</view>
        </view>

        <!-- 评论内容 -->
         <view v-if="tabIndex == 1" class="comment-box">
            <view class="trends" v-for="item in commentLsit" :key="item.id">
                <view class="trends-name">
                    <view class="trends-avatar">
                        <u-avatar class="avatar" size="40" :src="item.avatar"></u-avatar>
                        <view class="trends-name-text">{{ item.createName }}</view>
                    </view>
                    <view class="trends-customer"><u-icon name="calendar" color="#677585" size="20"></u-icon><text>{{ item.createTime }}</text></view>
                </view>
                <view class="trends-describe">{{ item.commentContent }}</view>
            </view>
            <uni-load-more :status="status" />
         </view>
         <!-- 更多信息 -->
         <view v-if="tabIndex == 2" class="item-content">
            <view class="item-content-row">
                <view>跟进类型</view>
                <view>{{ bus_followup_type[detailsData.followupType] }}</view>
            </view>
            <!-- <view class="item-content-row">
                <view>跟进方式</view>
                <view>---</view>
            </view> -->
            <view class="item-content-row">
                <view>跟进时间</view>
                <view>{{ detailsData.followupTime }}</view>
            </view>
            <view class="item-content-row">
                <view>跟进描述</view>
                <view>{{ detailsData.followupContent }}</view>
            </view>
            <view class="item-content-row">
                <view>客户名称</view>
                <view>{{ detailsData.customerName }}</view>
            </view>
            <view class="item-content-row">
                <view>客户状态</view>
                <view>{{ bus_customer_status[detailsData.customerStatus] }}</view>
            </view>
            <view class="item-content-row">
                <view>评论数量</view>
                <view>{{ detailsData.commentNumber }}</view>
            </view>
            <view class="item-content-row">
                <view>跟进人员</view>
                <view>{{ detailsData.staffName }}</view>
            </view>
            <view class="item-content-row">
                <view>创建时间</view>
                <view>{{ detailsData.createTime }}</view>
            </view>
        </view>
         
         <!-- 底部 -->
         <view class="bottom-box">
            <u-icon name="chat" color="#0C1019" size="24"></u-icon>
            <text @click="openPopup()">评论</text>
        </view>

        <!-- 弹出框 -->
        <uni-popup ref="popup" type="bottom" background-color="#fff" border-radius="10px 10px 0 0">
            <view class="popup-box">
                <u--input
                    placeholder="评论几句再走～"
                    border="surround"
                    v-model="commentContent"
                ></u--input>
                <u-button @click="addCommentContent()" class="submit-btn" color="#4DACB1FF" type="primary" shape="circle" text="提交"></u-button>
            </view>
        </uni-popup>
    </view>
</template>

<script>
import { convertToDict } from '@/common/utils'
export default {
    data() {
        return {
            tabList: [
                { name: '评论列表', type: 1 },
                { name: '更多信息', type: 2 }
            ],
            detailsData: {},
            id: null,
            tabIndex: 1,
            commentContent: '',
            commentForm: {
                recordId: null,
                pageNum: 1,
                pageSize: 10
            },
            commentLsit: [],
            total: 0,
            status: 'loading'
        }
    },
    onLoad(options) {
        this.id = options.id
        this.commentForm.recordId = options.id
        this.getDetails()
        this.comment()
        // 客户状态
        this.bus_customer_status = convertToDict(JSON.parse(uni.getStorageSync('bus_customer_status')))
        // 跟进类型
        this.bus_followup_type = convertToDict(JSON.parse(uni.getStorageSync('bus_followup_type')))
    },
    methods: {
        getDetails() {
			this.$http.get('/app/followup_record/' + this.id, {}).then(res => {
				if (res.code == 200) {
                    this.detailsData = res.data
				} else {
					uni.$u.toast(res.msg)
				}
			})
		},
        addCommentContent() {
            this.$http.post('/app/followup_evaluation', { recordId: this.id, commentContent: this.commentContent }).then(res => {
				if (res.data.code == 200) {
                    uni.showToast({ title: '评论成功', duration: 1000 });
                    this.commentContent = ""
                    this.commentForm.pageNum = 1
                    this.commentLsit = []
                    this.comment()
                    this.$refs.popup.close()
				} else {
					uni.$u.toast(res.msg)
				}
			})
        },
        comment() {
			this.$http.get('/app/followup_evaluation/list', this.commentForm).then(res => {
                console.log(res)
				if (res.code == 200) {
                    this.commentLsit = [...this.commentLsit, ...res.rows]
                    if (this.total > this.commentLsit.length) {
						console.log('有更多数据')
						this.status = 'more'
					} else {
						console.log('没更多数据')
						this.status = 'noMore'
					}
				} else {
					uni.$u.toast(res.msg)
				}
			})
		},
        onReachBottom() {
            if(tabIndex == 2) return
            console.log('上拉加载onReachBottom')
            if (this.status == 'noMore' || this.status == 'loading') return
            this.commentForm.pageNum = this.commentForm.pageNum + 1
            this.status = 'loading'
            this.comment()
        },
        addOrder() {
            uni.navigateTo({
                url: '/pages/order/addOrder'
            });
        },
        search() { },
        seeMoney() {
            this.$refs.popup.open()
        },
        closePopup() {
            this.$refs.popup.close()
        },
        goDetails(index) {
            uni.navigateTo({
                url: '/pages/crm/customer/customerDetails'
            });
        },
        openPopup() {
            this.$refs.popup.open()
        },
        backHandle() {
            uni.navigateBack()
        }
    }
}
</script>

<style lang="scss" scoped>
/deep/.uni-navbar__header-btns-right {
    width: 64px !important;
}
.followDetails {
    padding-bottom: 120rpx;
}
.trends {
    border-radius: 24rpx;
    background: rgba(255, 255, 255, 1);
    margin-top: 32rpx;
    padding: 32rpx;
    margin-bottom: 24rpx;

    .trends-name {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 28rpx;
        .trends-avatar {
            flex: 1;
            display: flex;
            align-items: center;
            margin-right: 16rpx;
            .trends-name-text {
                margin-left: 8rpx;
                flex: 1;
                width: 0;
                font-size: 30rpx;
                font-weight: 500;
                color: rgba(12, 16, 25, 1);
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }

        }
        .trends-customer {
            display: flex;
            align-items: center;
            margin-left: 20rpx;
            text-align: right;
            font-size: 28rpx;
            font-weight: 400;
            color: rgba(103, 117, 133, 1);
        }
    }

    .trends-describe {
        font-size: 32rpx;
        font-weight: 500;
        color: rgba(12, 16, 25, 1);
        margin-bottom: 20rpx;
    }

    .trends-state {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 28rpx;
        font-weight: 500;
        color: rgba(103, 117, 133, 1);
        >view:nth-child(1) {
            display: flex;
            align-items: center;
        }
    }
}
.tab-box {
    background: rgba(255, 255, 255, 1);
    display: flex;
    padding: 28rpx 32rpx;
    view {
        margin-right: 40rpx;
        font-size: 28rpx;
        font-weight: 400;
        color: rgba(103, 117, 133, 1);
    }
    .active {
        color: rgba(77, 172, 177, 1);
    }
}
.item-content {
    background: rgba(255, 255, 255, 1);
    padding: 0 32rpx;
    border-radius: 24rpx;

    .item-content-row {
        display: flex;
        justify-content: space-between;
        padding: 26rpx 0;
        font-size: 28rpx;
        border-bottom: 2rpx solid rgba(240, 240, 240, 1);

        >view:nth-child(1) {
            font-weight: 400;
            color: rgba(103, 117, 133, 1);
            width: 140rpx;
        }

        >view:nth-child(2) {
            flex: 1;
            font-weight: 500;
            color: rgba(12, 16, 25, 1);
            // 超出隐藏显示省略号
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            text-align: right;
        }
    }
}
.bottom-box {
    height: 44px;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0px 0px 12rpx rgba(0, 0, 0, 0.1);

    text {
        font-size: 28rpx;
        font-weight: 500;
    }

}

.popup-box {
    padding: 32rpx;
    display: flex;
    .submit-btn {
        width: 150rpx; margin-left: 20rpx;
    }
}
</style>